<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import http from '../../utils/http'

const route = useRoute()
const list = ref([])
const listType = ref('')

const getUserList = async () => {
  const type = route.query.type || 'fans'
  listType.value = type === 'fans' ? '粉丝' : '关注'
  
  const response = await http.get('/user/list', {
    params: { type }
  })
  list.value = response.data
}

onMounted(() => {
  getUserList()
})
</script>

<template>
  <div class="user-list-container">
    <h1>我的{{ listType }}</h1>
    <el-row :gutter="20">
      <el-col 
        v-for="user in list" 
        :key="user.id" 
        :xs="24" :sm="12" :md="8" :lg="6"
        class="user-card"
      >
        <el-card shadow="hover">
          <div class="user-content">
            <el-avatar :size="60" :src="user.avatar" />
            <div class="user-info">
              <h3>{{ user.username }}</h3>
              <p class="meta">
                <span>性别：{{ user.gender }}</span>
                <!-- 根据类型显示不同数据 -->
                <template v-if="listType === '粉丝'">
                  <el-divider direction="vertical" />
                  <span>粉丝数：{{ user.fans }}</span>
                </template>
                <template v-else>
                  <el-divider direction="vertical" />
                  <span>关注数：{{ user.following }}</span>
                </template>
              </p>
            </div>
            <el-button 
              type="primary" 
              @click="$router.push(`/user/${user.id}`)"
              plain
            >
              查看详情
            </el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>
.user-list-container {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.user-card {
  margin-bottom: 20px;
}

.user-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.user-info {
  h3 {
    margin: 8px 0;
  }
  
  .meta {
    color: #666;
    font-size: 0.9em;
    margin: 6px 0;
  }
}
</style>